package com.mg.game.content.gamescreen;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import com.mg.framework.kernel.CommandEnum;
import com.mg.framework.kernel.Screen;
import com.mg.framework.tiled.MapObject;

public class PlayerTank extends GameActor {

	public PlayerTank(Screen screen, Bitmap bitmap, MapObject mapObject) {
		super(screen, bitmap, mapObject);
	}

	@Override
	public void gameUpdate() {
		this.Rotate(this.degree, this.width / 2, this.height / 2);
		this.move();
	}

	private void move() {
		this.launch();
		if (this.tmpSpeedX != 0 && !GameActor.collisionDetection.isOverX(this)) {
			if ((this.tmpSpeedX < 0 && !GameActor.collisionDetection.hitLeft(
					this, "mapLayer", "ALL"))
					|| (this.tmpSpeedX > 0 && !GameActor.collisionDetection
							.hitRight(this, "mapLayer", "ALL"))) {
				this.addX(this.tmpSpeedX);
			}
		}
		if (this.tmpSpeedY != 0 && !GameActor.collisionDetection.isOverY(this)) {
			if ((this.tmpSpeedY < 0 && !GameActor.collisionDetection.hitTop(
					this, "mapLayer", "ALL"))
					|| (this.tmpSpeedY > 0 && !GameActor.collisionDetection
							.hitBottom(this, "mapLayer", "ALL"))) {
				this.addY(this.tmpSpeedY);
			}
		}
	}

	@Override
	public void screenUpdate(Canvas canvas) {
		this.drawSelf(canvas, null);

	}

	public void executeMoveCommand(CommandEnum commandState) {
		this.speed = 2f;
		if (commandState == CommandEnum.top) {
			this.degree = 0;
			this.setSpeedXY(0, -this.speed);
		} else if (commandState == CommandEnum.bottom) {
			this.degree = 180;
			this.setSpeedXY(0, this.speed);
		} else if (commandState == CommandEnum.left) {
			this.degree = -90;
			this.setSpeedXY(-this.speed, 0);
		} else if (commandState == CommandEnum.right) {
			this.degree = 90;
			this.setSpeedXY(this.speed, 0);
		} else if (commandState == CommandEnum.none) {
			this.speed = 0;
			this.setSpeedXY(this.speed, this.speed);
		}
	}

	public void executeOkCommand(CommandEnum commandState) {
		if (commandState == CommandEnum.down) {

		}
	}
}
